package com.xxmw.transaction.service.robot;

import com.baomidou.mybatisplus.core.toolkit.Sequence;
import com.baomidou.mybatisplus.extension.service.IService;
import com.xxmw.transaction.common.entity.P;
import com.xxmw.transaction.model.robot.RobotOrder;
import com.xxmw.transaction.vo.ClassifyVolumeVo;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 机器人订单服务
 * @author luowenliang
 * @since 2020/2/17 15:52
 */
public interface RobotOrderService extends IService<RobotOrder> {

    String HIGHEST_ORDER = ":highest:order";
    String LOWEST_ORDER = ":lowest:order";
    String TIMES_TAKE_ORDER = ":times:take:order";

     Sequence sequence = new Sequence();

    /**
     * 交易所订单列表
     * @param pageNum
     * @param pageSize
     * @param id
     * @param bourse
     * @return
     */
    P<RobotOrder> pageList(Integer pageNum, Integer pageSize, Long id, String ourId, Integer bourse, Integer status, String symbol);

    /**
     * 根据订单状态期望值更新订单状态
     * 解决取消订单后 订单详情定时任务任务又会更该订单状态
     * @param expected
     */
    int updateByIdAndExpected (RobotOrder order, Integer expected);

    RobotOrder getMaxBuyPriceOrder (Integer bourser, String symbol);

    RobotOrder getMinSellPriceOrder (Integer bourser, String symbol);

    /**
     * 机器人挂单（包含买卖）
     * @param bourse
     * @param symbol btcusdt
     */
    void volumeOrder (Integer bourse, String symbol, int jobTimes);

    /**
     * 根据状态获取所有订单
     * @param status
     * @return
     */
    List<RobotOrder> getOrderByStatus (Integer ...status);

    /**
     * 判断该笔订单是否需要撤销
     * @param bourse
     * @param symbol
     * @param isBuy 买单 or 卖单
     * @return
     */
    boolean needCancel (Integer bourse, String symbol, boolean isBuy);

    /**
     * 缓存成交量
     * @param bourse
     * @param symbol
     * @param num
     * @return
     */
    void volumeSet (Integer bourse, String symbol, BigDecimal num);

    /**
     * 清空订单缓存
     * @param bourse
     * @param symbol
     */
    void clearRecentlyOrder (Integer bourse, String symbol, boolean isBuy);

    /**
     * 成交量统计
     * @return
     */
    ClassifyVolumeVo volumeStatistics ();

    /**
     * CTC挂单量统计
     * @return
     */
    Map<String, Object> ctcOrderNumCount ();

    /**
     * 手续费统计
     * @return
     */
    Map<String, Object> feeCount ();
}
